<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>flask-web</title>
</head>
<body>
<input id="input" type="text" />
<button onclick="send()">Send</button>
<pre id="output"></pre>
</body>
<script src="/ws/iris-ws.js"></script>

<script>
    var wsURL = "ws://localhost:9090/ws/gchat"

    console.log("wsURL=",wsURL)

    var input = document.getElementById("input");
    var output = document.getElementById("output");

    var socket = new Ws(wsURL)
    socket.OnConnect(function () {
        output.innerHTML += "连接成功\n";
    });

    socket.OnDisconnect(function () {
        output.innerHTML += "连接失败\n";
    });

    socket.On("chat", function (msg) {
        addMessage(msg);
    });

    function send() {
        addMessage("我: " + input.value);
        socket.Emit("chat", input.value);
        input.value = "";
    }

    function addMessage(msg) {
        output.innerHTML += msg + "\n";
    }
</script>

</html>